import { createRouter, createWebHistory } from "vue-router";

const routes = [
  {
    path: "/",
    name: "applyShare",
    component: () => import("../views/applyShare/index.vue"),
    meta: { title: "申请分享员" },
  },
  {
    path: "/pdfPage",
    name: "pdfPage",
    component: () => import("../views/pdfPage/index.vue"),
  },
  {
    path: "/register",
    name: "registerPage",
    component: () => import("../views/register/index.vue"),
  },
];

const router = createRouter({
  history: createWebHistory(),
  routes,
  scrollBehavior() {
    return { left: 0, top: 0 };
  },
});

// 设置页面标题
router.beforeEach((to, from, next) => {
  document.title = to.meta.title || "";
  let url = window.location.href;
  const extensionRegex = /\.txt$/; // 正则表达式匹配.txt结尾
  if (!extensionRegex.test(url)) {
    next();
  } else {
    window.location.href = url;
  }
});

export default router;
